#include "helper.h"
#include "monitor.h"
#include "reg.h"
#include "golden_trace.h"
extern uint32_t instr;
extern char assembly[80];

/* decode I-type instrucion with unsigned immediate */
static void decode_j_type(uint32_t instr) {

	op_src1->type = OP_TYPE_JUMP;
	op_src1->imm = (instr & INDEX_MASK);
	op_src1->val = op_src1->imm;
}

make_helper(j) {

    decode_j_type(instr);
    uint32_t target = (cpu.pc & 0xF0000000) | (op_src1->val << 2);
    cpu.pc = target - 4;
    sprintf(assembly, "j   0x%08x", target);
}

make_helper(jal) {

    decode_j_type(instr);
    cpu.ra = cpu.pc + 8;
    uint32_t target = (cpu.pc & 0xF0000000) | (op_src1->val << 2);
    cpu.pc = target - 4;
    sprintf(assembly, "jal   0x%08x", target);
}